<template>
  <view
    class="content ba_img"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#eeeeee"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">图书林</view>
    </view>
    <view  class="box_inp_view" :style="{marginTop:inputMargen+'px'}">
      <view class="box_inp">
        <u--input
          placeholder="搜索你喜欢的图书"
          border="none"
          placeholderStyle="font-size:30rpx;color:#ADADAD;"
          prefixIcon="search"
          prefixIconStyle="font-size: 42rpx;color: #ADADAD"
          color="#ADADAD"
          v-model="value"
          @change="change"
          inputAlign="left"
          @confirm="confirm"
        ></u--input>
      </view>
    </view>

    <scroll-view
      class="box"
      :style="{
        height: scrollHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
    >
      <view
        class="box_item"
        v-for="(item, index) in list"
        :key="index"
        @click="toDetail(item)"
      >
        <view class="item_left" v-if="item.img">
          <image :src="item.img.external_url" mode=""></image>
        </view>
        <view class="item_right">
          <view class="right_title">
            {{ item.name }}
          </view>
          <view class="right_author" v-if="item.kecheng && item.kecheng[0]"> 关联课程：{{item.kecheng[0].name}} </view>
          <view class="right_text" v-html="item.introduce">
            <!-- {{ item.introduce }} -->
          </view>
        </view>
      </view>
	  <view style="height:30rpx"></view>
    </scroll-view>


    <floatingBall></floatingBall>
  </view>
</template>

<script>
import { getList } from "@/common/api/tushu.js";
export default {
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      scrollHeihgt: 0,
	  inputMargen:0,
      value: "",
      itemList: [{}, {}],
      list: [],
    };
  },
  created() {
    // const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    // this.statusBarHeight = statusBarHeight.statusBarHeight;
    // this.$nextTick(() => {
    //   uni
    //     .createSelectorQuery()
    //     .select(".head")
    //     .boundingClientRect((data) => {
    //       this.height = data.height;
    //     })
    //     .exec();
    // });
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.windowHeihgt =
      statusBarHeight.windowHeight - statusBarHeight.statusBarHeight;
    console.log(statusBarHeight.windowHeight, "总高度");
    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".box_inp_view").fields({
        size: true,
      });

      query.exec((data) => {
        console.log(data, "各种高度");
        let sum = 0;
        data.forEach((item) => {
          if (item != null) {
            sum += item.height;
          }
        });
		this.inputMargen = data[0].height
        this.scrollHeihgt = this.windowHeihgt - sum;
        console.log(this.scrollHeihgt, "滚动区高度");
        // this.height = sum + 20;
        // console.log(data,'这个是啥')
      });
    });
  },
  onLoad() {
    this.getList();
  },
  methods: {
    scroll() {},
	// 搜索
	change(){
		this.getList()
	},
    getList() {
      getList({
        search: this.value,
      })
        .then((res) => {
          console.log("reeeeeees", res);
          this.list = res.data.list.data;
        })
        .catch((err) => {
          this.$u.toast(err);
        });
    },
    click(e) {
      console.log("eeeee", e);
    },
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    confirm() {
      this.getList();
    },
    toDetail(item) {
      uni.navigateTo({
        url: "/pages/book/detail?type=1&id=" + item.id,
      });
    },
  },
};
</script>

<style scoped lang="scss">
.ba_img {
  position: fixed;
  margin: 0;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
  box-sizing: border-box;
}

.head {
  width: 100%;
  padding: 18rpx 0 47rpx;
  position: fixed;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}
.box_inp_view {
  padding: 0 30rpx 30rpx 30rpx;
  box-sizing: border-box;
   .box_inp {
    width: 100%;
    height: 80rpx;
    background: rgba(39, 44, 41, 0.5);
    border-radius: 40rpx;
    display: flex;
    align-items: center;
    margin-top: 32rpx;
    padding: 0 32rpx;
    box-sizing: border-box;
  }
}

.box {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;


  .box_item {
    width: 100%;
    display: flex;
    margin-top: 32rpx;
    background: rgba(39, 39, 39, 0.5);
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 32rpx;
    box-sizing: border-box;

    .item_left {
      width: 160rpx;
      height: 214rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    .item_right {
      flex: 1;
      padding-left: 24rpx;
      box-sizing: border-box;
      position: relative;

      .right_title {
        font-size: 32rpx;
        font-family: PingFang SC-Medium, PingFang SC;
        font-weight: 400;
        color: #eeeeee;
      }

      .right_author {
        font-size: 26rpx;
        font-family: PingFang SC-Medium, PingFang SC;
        font-weight: 400;
        color: #adadad;
      }

      .right_text {
        font-size: 26rpx;
        font-family: PingFang SC-Medium, PingFang SC;
        font-weight: 400;
        color: #eeeeee;
        position: absolute;
        bottom: 0;
        overflow: hidden;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
      }
    }
  }
}
</style>